<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>条件和循环</title>
</head>
<body>
  <!-- 标准语法 -->
  <!-- 判断 -->
  {{if age < 10}}
  <div>儿童</div>
  {{else if age<20}}
  <div>少年</div>
  {{else if age<30}}
  <div>青年</div>
  {{else}}
  <div>老年</div>
  {{/if}}
  {{if users.length==0}}
  <div>暂无数据</div>
  {{/if}}
  <!-- 循环
    each 用于循环，它默认的元素变量名称为 $value,默认的索引名称 $index
    each 变量 value key
  -->
  {{each users}}
    <li>{{$index}} -- {{$value.name}}</li>
  {{/each}}
  {{each users item key}}
    <li>{{key}} -- {{item.name}}</li>
  {{/each}}
  <hr>
  <!-- 原始语法 -->
  <%if(age<10){%>
    <div>儿童</div>
  <%}else if(age<20){%>
    <div>少年</div>
  <%}else if(age<30){%>
    <div>青年</div>
  <%}else{%>
    <div>老年</div>
  <%}%>
  <%if(users.length==0){%>
    <div>没有数据</div>
  <%}%>
  <!-- 循环 -->
  <%users.forEach(item=>{%>
    <li><%=item.name%></li>
  <%})%>
  <%for(let {name} of users){%>
    <li><%=name%></li>
  <%}%>
</body>
</html>